package com.qingke.example;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class GetMessageServlet
 */
@WebServlet("/GetMessageServlet")
public class GetMessageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public GetMessageServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
         List<String> msgs=(List<String>)request.getServletContext().getAttribute("chat");
         if(msgs==null){
        	 msgs=new ArrayList<String>();
         }
         String allmsg ="";
         for(String msg:msgs){
        	 allmsg +=msg+"||";
         }
         allmsg =allmsg.equals("")?allmsg:allmsg.substring(0,allmsg.length()-2);
         response.getWriter().println(allmsg);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
